package test;

import model.Business;
import model.Food;
import view.BusinessView;
import view.FoodView;
import view.impl.BusinessViewImpl;
import view.impl.FoodViewImpl;

import java.util.List;
import java.util.Scanner;

public class ElemeBusinessSystem {
    /**
     * @author cyc20
     */

    public static void main(String[] args) {
        System.out.println("---------------------------------------------------------");
        System.out.println("|\t\t\t 饿了么后台商户系统  \t\t\t|");
        System.out.println("---------------------------------------------------------");
        BusinessView businessView=new BusinessViewImpl();
        int errorN=0;
        Business business=null;
        while (true){
            business=businessView.login();
            if(business!=null){
                System.out.println("登陆成功");
                break;
            }else {
                errorN++;
                if(errorN==3){
                    System.out.println("已经错误3次，系统自动退出。");
                    return;
                }
                System.out.println("账号信息不对，请重新输入。");
            }
        }
        Scanner sc=new Scanner(System.in);
        while (true){
            System.out.println("======= 一级菜单（商家管理）" +
                    "\n=======1.查看商家信息\n=======2.修改商家信息\n=======3.更新密码\n=======4.所属商品管理\n=======5.退出系统\n=======");
            System.out.println("请输入你的选择：");
            int n=Integer.parseInt(sc.nextLine());
            if(n==1){
                businessView.showBusiness(business.getBusinessId());
            }else if(n==2){
                businessView.editBusiness(business.getBusinessId());
            }else if(n==3){
                businessView.updateBusinessByPassword(business.getBusinessId());
            }else if(n==4){
                foodManager(business);
            }else if(n==5){
                System.out.println("谢谢使用");
                return ;
            }else{
                System.out.println("输入错误，请重新输入。");
            }
        }
    }

    private static void foodManager(Business business) {
        FoodView foodView=new FoodViewImpl();
        while (true){
            System.out.println("======= 二级菜单（食品管理）");
            System.out.println("======= 1.查看食品列表");
            System.out.println("======= 2.新增食品");
            System.out.println("======= 3.修改食品");
            System.out.println("======= 4.删除食品");
            System.out.println("======= 5.返回一级菜单");
            Scanner sc=new Scanner(System.in);
            int n=Integer.parseInt(sc.nextLine());
            if(n==1){
                List<Food> list = foodView.showFoodList(business.getBusinessId());
                if(list!=null&&list.size()>0){
                    for (int i = 0; i < list.size(); i++) {
                        System.out.println(list.get(i));
                    }
                }else{
                    System.out.println("暂无数据");
                }

            }else if(n==2) {
                foodView.saveFood(business.getBusinessId());
            }else if(n==3) {
                foodView.updateFood(business.getBusinessId());
            }else if(n==4) {
                foodView.removeFood(business.getBusinessId());
            }else if(n==5) {
                return ;
            }else {
                System.out.println("输入错误，请重新输入。");
            }
        }


    }
}
